package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.TeacherRequestVO;
import com.yugong.entity.vo.response.TeacherListResponseVO;
import com.yugong.service.TeacherService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教师控制器类
 *
 * @author yugong
 * @date 2024/2/18
 */
@RestController
@RequestMapping("/api/teacher")
public class TeacherController {
    @Resource
    private TeacherService teacherService;

    /**
     * 根据订单班管理员工号查询教师
     *
     * @param orderClassAdminNo 订单班管理员工号
     * @return 教师
     */
    @GetMapping("/find-teacher-order-class-admin-no")
    public Result findTeacherByOrderClassAdminNo(@RequestParam String orderClassAdminNo) {
        List<TeacherListResponseVO> teacherListResponseVOList = teacherService.findTeacherByOrderClassAdminNo(orderClassAdminNo);
        return Result.success(teacherListResponseVOList);
    }

    /**
     * 根据教师名查询教师信息
     *
     * @param pageNum     当前页
     * @param pageSize    当前页的数据总数
     * @param teacherName 教师名
     * @return 教师信息
     */
    @GetMapping("/find-teacher-page")
    public Result findTeacherPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "5") Integer pageSize,
                                  @RequestParam String teacherName) {
        PageInfo<TeacherListResponseVO> teacherListResponseVOPageInfo = teacherService.findTeacher(pageNum, pageSize, teacherName);
        return Result.success(teacherListResponseVOPageInfo);
    }

    /**
     * 删除教师
     *
     * @param teacherNo 工号
     * @return 响应码
     */
    @DeleteMapping("/delete-teacher/{teacherNo}")
    public Result deleteTeacher(@PathVariable String teacherNo) {
        int deleteFlag = teacherService.deleteTeacher(teacherNo);
        return Result.success(deleteFlag);
    }

    /**
     * 查询教师个人信息
     *
     * @param teacherNo 工号
     * @return 教师个人信息
     */
    @GetMapping("/teacher-info/{teacherNo}")
    public Result teacherInfo(@PathVariable String teacherNo) {
        TeacherListResponseVO teacherListResponseVO = teacherService.TeacherInfo(teacherNo);
        return Result.success(teacherListResponseVO);
    }

    /**
     * 修改信息
     *
     * @param teacherRequestVO 教师请求实体类
     * @return 响应码
     */
    @PutMapping("/update-info")
    public Result updateInfo(@RequestBody TeacherRequestVO teacherRequestVO) {
        int updateFlag = teacherService.updateInfo(teacherRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 修改教师
     *
     * @param teacherRequestVO 教师请求实体类
     * @return 响应码
     */
    @PutMapping("/update-teacher")
    public Result updateTeacher(@RequestBody TeacherRequestVO teacherRequestVO) {
        int updateFlag = teacherService.updateTeacher(teacherRequestVO);
        return Result.success(updateFlag);
    }
}
